extends Area2D


@export var is_die :bool = false
@export var animate :AnimatedSprite2D
@export var collision :CollisionShape2D

func _physics_process(delta: float) -> void:
	if is_die !=true:
		position+=Vector2(-30,0)*delta
		
	else:  
		animate.play("die")
		position+=Vector2(0,0)
		collision.disabled =true
		await get_tree().create_timer(1).timeout
		queue_free()
	if position.x<420:
		queue_free()

func _on_area_entered(area: Area2D) -> void:
	if area is Area2D:
		is_die = true
		$death.play()
		get_tree().current_scene.score +=1
		print(get_tree().current_scene.score)
		area.queue_free()


func _on_body_entered(body: Node2D) -> void:
	print("玩家碰到slime")
	if body is CharacterBody2D and not is_die:
		body.game_over()
